package ${package.Controller?replace(".controller","")}.config.mybatisplus;


import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

import javax.sql.DataSource;

/**
* @author yiming
* @description: TODO
* @date ${date}
*/
@Configuration
public class MybatisPlusConfig {

/**
* 分页插件
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
@Bean
public DefaultSqlInjector defaultSqlInjector(){
return new DefaultSqlInjector();
}
@Bean
@Primary
public SqlSessionFactory sqlSessionFactory(DataSource dataSource,PaginationInterceptor paginationInterceptor) throws Exception {
MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
Resource[] rs= new PathMatchingResourcePatternResolver().getResources("classpath:mapping/*.xml");
sqlSessionFactoryBean.setMapperLocations(rs);
sqlSessionFactoryBean.setPlugins(new Interceptor[]{paginationInterceptor});
return sqlSessionFactoryBean.getObject();
}}
}
